package main.java.org.controller;

import lombok.extern.slf4j.Slf4j;
import main.java.Exam.pojo.tableDTO.UserDTO;
import main.java.Exam.pojo.tableVO.UserVO;
import main.java.org.result.Result;
import main.java.org.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
//登入接口
    @PostMapping("/login")
    public Result<UserVO> login(@RequestBody UserDTO userDTO) {
        log.info("正在登入");
        UserVO userVO = userService.login(userDTO);
        return Result.success(userVO);
    }
//注册接口
@PostMapping("/register")
public Result<String> register(@RequestBody  UserDTO userDTO) { // @Valid 触发DTO参数校验
    log.info("用户注册：{}", userDTO.getUsername());
    userService.register(userDTO);
    return Result.success("注册成功");
}


}
